<?php
/**
* @file $Id: TeacherCompletion.php 205 2006-09-27 16:29:46Z focus-sis $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

if(!$_REQUEST['mp'])
	$_REQUEST['mp'] = UserMP();

$QI = DBQuery("SELECT PERIOD_ID,TITLE FROM SCHOOL_PERIODS WHERE SCHOOL_ID='".UserSchool()."' AND SYEAR='".UserSyear()."' ORDER BY SORT_ORDER ");
$period_RET = DBGet($QI);

$period_select =  "<SELECT name=period><OPTION value=''>"._('All')."</OPTION>";
foreach($period_RET as $period)
	$period_select .= "<OPTION value=$period[PERIOD_ID]".(($_REQUEST['period']==$period['PERIOD_ID'])?' SELECTED':'').">".$period['TITLE']."</OPTION>";
$period_select .= "</SELECT>";

$sem = GetParentMP('SEM',UserMP());
$mp_select = "<SELECT name=mp><OPTION value=".UserMP().">".GetMP(UserMP())."</OPTION><OPTION value=".$sem.(($sem==$_REQUEST['mp'])?' SELECTED':'').">".GetMP($sem)."</OPTION><OPTION value=E".$sem.(('E'.$sem==$_REQUEST['mp'])?' SELECTED':'').">".GetMP($sem).' '._('Exam').'</OPTION>';

$pro = GetChildrenMP('PRO',UserMP());
$pros = explode(',',str_replace("'",'',$pro));
$pro_grading = false;
$pro_select = '';
foreach($pros as $pro)
{
	if(GetMP($pro,'POST_START_DATE'))
	{
		if(!$_REQUEST['mp'])
			$_REQUEST['mp'] = $pro;

		$mp_select .= "<OPTION value=".$pro.(($pro==$_REQUEST['mp'])?' SELECTED':'').">".GetMP($pro)."</OPTION>";
	}
}

$mp_select .= '</SELECT>';

DrawHeader(ProgramTitle());
echo "<FORM action=Modules.php?modname=$_REQUEST[modname] method=POST>";
DrawHeader($mp_select.' - '.$period_select,'<INPUT type=submit value='._('Go').'>');
echo '</FORM>';

$sql = "SELECT s.STAFF_ID,s.LAST_NAME||', '||s.FIRST_NAME AS FULL_NAME,sp.TITLE,cp.PERIOD_ID 
		FROM USERS s,COURSE_PERIODS cp,SCHOOL_PERIODS sp 
		WHERE 
			sp.PERIOD_ID = cp.PERIOD_ID AND cp.DOES_GRADES='Y'
			AND cp.TEACHER_ID=s.STAFF_ID AND cp.MARKING_PERIOD_ID IN (".GetAllMP('QTR',UserMP()).") 
			AND cp.SYEAR='".UserSyear()."' AND cp.SCHOOL_ID='".UserSchool()."' AND s.PROFILE='teacher'
			".(($_REQUEST['period'])?" AND cp.PERIOD_ID='$_REQUEST[period]'":'')."
			AND NOT EXISTS (SELECT '' FROM GRADES_COMPLETED ac WHERE ac.STAFF_ID=cp.TEACHER_ID AND ac.MARKING_PERIOD_ID='$_REQUEST[mp]' AND ac.PERIOD_ID=sp.PERIOD_ID)
		";
$RET = DBGet(DBQuery($sql),array(),array('STAFF_ID','PERIOD_ID'));

if(count($RET))
{
	foreach($RET as $staff_id=>$periods)
	{
		$i++;
		$staff_RET[$i]['FULL_NAME'] = $periods[key($periods)][1]['FULL_NAME'];
		foreach($periods as $period_id=>$period)
		{
			$staff_RET[$i][$period_id] = '<IMG SRC=assets/x.gif>';
		}
	}
}

$columns = array('FULL_NAME'=>_('Teacher'));
if(!$_REQUEST['period'])
{
	foreach($period_RET as $period)
		$columns[$period['PERIOD_ID']] = $period['TITLE'];
}

ListOutput($staff_RET,$columns,_('Teacher who hasn\'t entered grades'),_('Teachers who haven\'t entered grades'));
?>